package algorithm.linkedlist;

/**
 * 链表节点类
 *
 * @author 杨 强
 * @package algorithm.linkedlist
 * @createTime 2023-03-09 21:43
 */
public class ListNode {
    // 值
    public int val;
    // 下一个节点
    public ListNode next;

    public ListNode() {}
    public ListNode(int val) {
        this.val = val;
    }
    public ListNode(int val, ListNode next) {
        this.val = val; this.next = next;
    }

    /**
     * 打印链表的方法
     * @return
     */
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder(64);
        sb.append("[");
        ListNode p = this;
        while (p != null){
            sb.append(p.val);
            if (p.next != null){
                sb.append(",");
            }
            p = p.next;
        }
        sb.append("]");
        return sb.toString();
    }
}
